package com.xymtop.Service;

import com.xymtop.Entity.Tea;
import com.xymtop.Vo.Teacher;
import com.xymtop.Server.Util.DBService;
import com.xymtop.Server.Util.Time;

import java.util.List;

/**
 * @ClassName : TeaService
 * @Description : 教师的操作函数
 * @Author : 肖叶茂
 * @Date: 2022/12/13  16:32
 */
public class TeaService {
    public Teacher login(String id, String password) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Teacher teacher = new Teacher();

        List<Object> objs =  DBService.Get("SELECT * FROM t_login WHERE `id` = "+id+" AND `password` = "+password+" AND `code` = 1", Teacher.class.getCanonicalName());
        if(objs.isEmpty()){
            return null;
        }else {
            return (Teacher) objs.get(0);
        }
    }

    //    注册
    public Tea regist(Tea teacher) throws ClassNotFoundException, InstantiationException, IllegalAccessException {

        if(teacher.id == null){
            teacher.setId(Time.getUnixTime());
        }


        if(teacher.code == null){
            teacher.setCode("1");
        }


        Boolean flag = DBService.InsertObject(teacher,"teachers");

        if(!flag){
            teacher = null;
        }
        return  teacher;
    }
}
